package cn.founder.basic.service.impl;

import cn.founder.basic.mapper.BaseMapper;
import cn.founder.basic.query.BaseQuery;
import cn.founder.basic.service.IBaseService;
import cn.founder.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> basemapper;

    @Override
    @Transactional
    public void add(T t) {
        basemapper.save(t);
    }

    @Override
    @Transactional
    public void del(Long id) {
        basemapper.del(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        basemapper.update(t);
    }

    @Override
    public T queeryById(Long id) {
        return basemapper.loadById(id);
    }

    @Override
    public List<T> queryAll() {
        return basemapper.loadAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        Long total = basemapper.queryCount(query);
        //使用mapper 方法查询分页信息填入，装入前端需要的data数据里面
        List<T> rows = basemapper.queryData(query);
        return new PageList<T>(total,rows);
    }

    @Override
    @Transactional
    public void pathchDel(List<Long> ids) {
        basemapper.pathchDel(ids);
    }
}
